package Schedulers;

import java.util.LinkedList;
import java.util.List;

import threadedSimulator.Cpu;

import Processes.Processes;

//The scheduler will be called each time the CPU receives a system timer 
//interrupt or a process makes a system call. It will determine what event 
//activated it and then determine which runnable process to execute next 
//(don't forget about the context switch). You should implement schedulers 
//		for the round-robin, priority, and lottery scheduling policies.

public class RoundRobinScheduler extends Scheduler {

	
	/**
	 * Constructs and initializes a new instance of the RoundRobinScheduler class.
	 * 
	 * @param the_cpu The Cpu to be associated with this RoundRobinScheduler.
	 */
	public RoundRobinScheduler(Cpu the_cpu) {
		super(the_cpu);
	}

	/**
	 * Adds the given process into the this RoundRobinScheduler's list of processes.
	 * 
	 * @param the_process The process to be added.
	 */
	public void addProcess(Processes the_process) {
		my_list_of_processes.add(the_process);
		my_log.add(the_process);
	}
	
	/**
	 * Halts the current process.
	 */
	public void haltCurrentProcess() {
		Processes last = my_list_of_processes.remove(0);
        last.running = false;
        if (!last.has_finished) {
    		addProcess(last);
        }
		my_list_of_processes.get(0).running = true;
		my_list_of_processes.get(0).run();
		my_cpu.addToOutput(toString(), "Scheduler");
	}

	@Override
	public boolean systemCall(Thread the_input) {
		// TODO Auto-generated method stub
		return false;
	}

	
	// public boolean systemCall(Runnable the_input)
	// {
	// return false;
	// }
}
